/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormHoras.java
 *
 * Created on 21/05/2012, 21:03:42
 */
package views;

import javax.swing.DefaultComboBoxModel;
import models.Horas;
import models.Projeto;
import models.Tarefa;

/**
 *
 * @author 40800431
 */
public class FormHoras extends javax.swing.JPanel {
    private MainWindow parentFrame;

    /** Creates new form FormHoras */
    public FormHoras(MainWindow parentFrame) {
        this.parentFrame = parentFrame;
        
        initComponents();
        
        DefaultComboBoxModel projetosModel = new DefaultComboBoxModel(Projeto.listAllAsArray());
        projetosModel.insertElementAt("Selecione um Projeto", 0);
        this.cboProjeto.setModel(projetosModel);
        this.cboProjeto.setSelectedIndex(0);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cboProjeto = new javax.swing.JComboBox();
        cboTarefa = new javax.swing.JComboBox();
        lblProjeto = new javax.swing.JLabel();
        lblTarefa = new javax.swing.JLabel();
        lblHoraInicio = new javax.swing.JLabel();
        lblHoraFim = new javax.swing.JLabel();
        lblHoraFim1 = new javax.swing.JLabel();
        txtDataTarefa = new javax.swing.JTextField();
        txtHoraInicio = new javax.swing.JTextField();
        txtHoraTermino = new javax.swing.JTextField();
        btnCadastrar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        cboProjeto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboProjetoActionPerformed(evt);
            }
        });

        cboTarefa.setEnabled(false);

        lblProjeto.setText("Projeto");

        lblTarefa.setText("Tarefa");

        lblHoraInicio.setText("Hora Início");

        lblHoraFim.setText("Hora Término");

        lblHoraFim1.setText("Data");

        txtDataTarefa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDataTarefaActionPerformed(evt);
            }
        });

        btnCadastrar.setText("Cadastrar");
        btnCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCadastrarActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(lblProjeto, javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(lblTarefa)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cboTarefa, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(btnCadastrar)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(1, 1, 1)
                                    .addComponent(cboProjeto, 0, 434, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(btnCancelar)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblHoraFim)
                            .addComponent(lblHoraFim1)
                            .addComponent(lblHoraInicio))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtHoraInicio, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
                            .addComponent(txtDataTarefa, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
                            .addComponent(txtHoraTermino, javax.swing.GroupLayout.Alignment.TRAILING))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblProjeto)
                    .addComponent(cboProjeto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTarefa)
                    .addComponent(cboTarefa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblHoraFim)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtDataTarefa, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblHoraFim1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lblHoraInicio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtHoraInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtHoraTermino, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCadastrar)
                    .addComponent(btnCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cboProjetoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboProjetoActionPerformed
        if(this.cboProjeto.getSelectedIndex() > 0){
            String selectedProject = this.cboProjeto.getSelectedItem().toString();

            String[] tarefas = Tarefa.listByProject(selectedProject);

            this.cboTarefa.setModel(new javax.swing.DefaultComboBoxModel(tarefas));
            this.cboTarefa.setEnabled(true);
        }else{
            this.cboTarefa.setEnabled(false);
            this.cboTarefa.setModel(new javax.swing.DefaultComboBoxModel());
        }
    }//GEN-LAST:event_cboProjetoActionPerformed

    private void txtDataTarefaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDataTarefaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDataTarefaActionPerformed

    private void btnCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCadastrarActionPerformed
        Horas novaHora = new Horas();
        
        
    }//GEN-LAST:event_btnCadastrarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCadastrar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JComboBox cboProjeto;
    private javax.swing.JComboBox cboTarefa;
    private javax.swing.JLabel lblHoraFim;
    private javax.swing.JLabel lblHoraFim1;
    private javax.swing.JLabel lblHoraInicio;
    private javax.swing.JLabel lblProjeto;
    private javax.swing.JLabel lblTarefa;
    private javax.swing.JTextField txtDataTarefa;
    private javax.swing.JTextField txtHoraInicio;
    private javax.swing.JTextField txtHoraTermino;
    // End of variables declaration//GEN-END:variables
}